const { sequelize } = require('../config/database');

async function updateSubscriptionStatusEnum() {
  try {
    console.log('开始更新subscription_status字段的ENUM值...');
    
    // 使用原生SQL来修改ENUM字段
    await sequelize.query(`
      ALTER TABLE user_benefits 
      MODIFY COLUMN subscription_status 
      ENUM('active', 'cancelled', 'past_due', 'unpaid', 'incomplete', 'incomplete_expired') 
      COMMENT 'Stripe订阅状态'
    `);
    
    console.log('subscription_status字段ENUM值更新成功！');
    console.log('新增状态: incomplete, incomplete_expired');
    
  } catch (error) {
    console.error('更新subscription_status字段失败:', error);
    throw error;
  }
}

// 如果直接运行此脚本
if (require.main === module) {
  updateSubscriptionStatusEnum()
    .then(() => {
      console.log('迁移完成');
      process.exit(0);
    })
    .catch((error) => {
      console.error('迁移失败:', error);
      process.exit(1);
    });
}

module.exports = { updateSubscriptionStatusEnum }; 